cmake_minimum_required(VERSION 3.0)

#先指定编译器，在执行cmake指令的时候，增加一个输入，-DBUILD_PLATFORM指定平台，支持windows（默认为64位）、linux-x86、linux-arm
if(${BUILD_PLATFORM} MATCHES "linux-arm")
    message("-- Build under the linux arm platform")
    set(CMAKE_SYSTEM_NAME ARM)
    set(CMAKE_SYSTEM_PROCESSOR $ENV{ARCH})
    #指定编译器
    set(ARM_TOOLCHAIN_PREFIX "/opt/gcc-linaro-6.5.0-2018.12-x86_64_aarch64-linux-gnu")
    set(CMAKE_FIND_ROOT_PATH ${ARM_TOOLCHAIN_PREFIX})
    set(CMAKE_C_COMPILER ${ARM_TOOLCHAIN_PREFIX}/bin/aarch64-linux-gnu-gcc)
    set(CMAKE_CXX_COMPILER ${ARM_TOOLCHAIN_PREFIX}/bin/aarch64-linux-gnu-g++)
    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
else()
    message("-- Build under the x86 platform")
    set(CMAKE_CXX_COMPILER g++)
    set(CMAKE_C_COMPILER gcc)
endif()

#指定版本信息
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_VERBOSE_MAKEFILE on)

add_compile_options(-fPIC)

if("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
    message("-- Build type is Release!")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -O3")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -O3")
else()
    message("-- Build type is Debug!")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -O1")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -Wall -O1")
endif()

project(VehicleCtrlTest)

file(GLOB_RECURSE ALL_HEADERS
    ${PROJECT_SOURCE_DIR}/src/*.h
    ${PROJECT_SOURCE_DIR}/src/*.hpp
    )

file(GLOB_RECURSE ALL_SOURCES 
    ${PROJECT_SOURCE_DIR}/src/*.cpp
    ${PROJECT_SOURCE_DIR}/src/*.cxx
    ${PROJECT_SOURCE_DIR}/src/*.cc
    ${PROJECT_SOURCE_DIR}/src/*.c
    )

include_directories(${PROJECT_SOURCE_DIR}/inc)
include_directories(${PROJECT_SOURCE_DIR}/src)

link_directories(${PROJECT_SOURCE_DIR}/lib)

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
add_executable(${PROJECT_NAME} ${ALL_SOURCES} ${ALL_HEADERS})

if(CMAKE_SYSTEM_NAME MATCHES "Windows")
    target_link_libraries(${PROJECT_NAME} m pthread -lws2_32 -lwsock32)
else()
    target_link_libraries(${PROJECT_NAME} m rt pthread)
endif()



#install(DIRECTORY ${PROJECT_SOURCE_DIR}/config/ DESTINATION ${EXECUTABLE_OUTPUT_PATH}/config)


